<template>
	<view id="balance-box" class="header-top-margin" :data-theme="themeStyle" >
		<!-- <view class="balance-wrap"> -->
			<!-- <view class="balance-top">
				<view class="balance-num">
					<view class="balance-tips balance-title">
						<text>{{ $lang('accountBalance') }}{{ $lang('money') }}</text>
					</view>
					<view class="all-alance">{{ (parseFloat(balanceInfo.balance) + parseFloat(balanceInfo.balance_money)).toFixed(2) }}</view>
				</view>
			</view> -->

			<!-- <block v-if="Development">
				<view class="balance_other">
					<view class="balance_allow">
						<view>{{ $lang('ableAccountBalance') }} {{ $lang('money') }}</view>
						<view class="font-size-toolbar">{{ balanceInfo.balance_money }}</view>
					</view>
					<view class="balance-split"></view>
					<view class="balance_unallow">
						<view>{{ $lang('noAccountBalance') }} {{ $lang('money') }}</view>
						<view class="font-size-toolbar">{{ balanceInfo.balance }}</view>
					</view>
				</view>
			</block> -->
		<!-- </view> -->

		<!-- <block v-if="Development">
			<view class="action_recode">
				<view @click="toBalanceDetail">
					<image :src="$util.img('upload/uniapp/member/balance_detail/recharge_detail.png')"></image>
					<text>{{ $lang('balanceDetailed') }}</text>
					<text class="iconfont iconright"></text>
				</view>
				<view v-if="addonIsExit.memberrecharge && memberrechargeConfig && memberrechargeConfig.is_use" @click="toOrderList">
					<image :src="$util.img('upload/uniapp/member/balance_detail/recharge_recode.png')"></image>
					<text>{{ $lang('rechargeRecord') }}</text>
					<text class="iconfont iconright"></text>
				</view>
			</view>
		</block> -->

		<!-- <block v-if="Development">
			<view class="action">
				<view @click="toList" class="recharge-withdraw color-base-bg" v-if="addonIsExit.memberrecharge && memberrechargeConfig && memberrechargeConfig.is_use">
					{{ $lang('recharge') }}
				</view>
				<view class="withdraw color-base-border color-base-text" v-if="addonIsExit.memberwithdraw && withdrawConfig && withdrawConfig.is_use" @click="toWithdrawal">
					{{ $lang('withdrawal') }}
				</view>
			</view>
		</block> -->
		
		<!-- new -->
		<!-- <header-back :headerTitle="'钱包管理'"></header-back> -->
		<header-top></header-top>
		<view class="blance-header">
			
			<view class="header-wrap header-wrap-bg">
				<view class="wrap-box">
					<view class="wrap" @click="toRoute('/pages/member/blance/points/list?type=1')">
						<view class="wrap-text">CLP</view>
						<view class="num wrap-text">{{walletObj.red_credit || 0}}</view>
					</view>
					<view class="wrap wrap-c" @click="toRoute('/pages/member/blance/points/list?type=2')">
						<view class="wrap-text">RP</view>
						<view class="num wrap-text">{{walletObj.white_credit || 0}}</view>
					</view>
					<!-- userInfo.member_level_name == '铂钻会员' -->
					<view class="wrap wrap-r" v-if="false" @click="toRoute('/pages/member/blance/points/list?type=3')">
						<view class="wrap-text">库存积分</view>
						<view class="num wrap-text">{{walletObj.stock_credit || 0}}</view>
					</view>
				</view>
				<view class="wrap-bom ">
					<view class="bom-box wrap-bd" @click="toRoute('/pages/member/blance/points/apply?type=1')">
						<image src="/static/icon/zhuanzhang_icon_05.png" class="bom-icon" mode=""></image>
						<view class="wrap-text">{{$lang('pointsToU')}}</view>
					</view>
					<!-- userInfo.member_level_name == '铂钻会员' -->
					<view class="bom-box bom-r" v-if="false" @click="toRoute('/pages/member/blance/points/apply?type=2')">
						<image src="/static/icon/zhuanzhang_icon_04.png" class="bom-icon" mode=""></image>
						<view class="wrap-text">{{ $lang('uAgainstInventoryPoints') }}</view>
					</view>
				</view>
			</view>
		</view>
		
		<view class="blance-content">
			<view class="user-box">
				<view class="price">{{ $lang('accountTotalUSDT') }}</view>
				<view class="user-price">{{walletObj.balance_total || 0}}</view>
				<view class="price">≈{{walletObj.balance_to_cny || 0}} CNY</view>
				<view class="user-wrap">
					<view class="user-item user-bd" @click="toRoute('/pages/member/blance/recharge')">
						<image src="/static/icon/zhuanzhan_icon_01.png" class="bi-icon" mode=""></image>
						<view class="user-text">{{ $lang('rechargeCurrency') }}</view>
					</view>
					<view class="user-item user-bd" @click="toRoute('/pages/member/blance/withdraw?type=1')">
						<image src="/static/icon/zhuanzhan_icon_03.png" class="bi-icon" mode=""></image>
						<view class="user-text">{{ $lang('withdrawalCurrency') }}</view>
					</view>
					<view class="user-item" @click="toRoute('/pages/member/blance/withdraw?type=2')">
						<image src="/static/icon/zhuanzhang_icon_02.png" class="bi-icon" mode=""></image>
						<view class="user-text">{{ $lang('transferCurrency') }}</view>
					</view>
				</view>
			</view>
			
			<view class="h-title">{{ $lang('assetList') }}</view>
			<view class="blance-ul">
				<view class="blance-li" v-for="(item,index) in walletArr" :key="index" @click="toDetail(item.money_type,'USDT')">
					<view class="li-top">
						<view class="left">
							<image :src="item.coin_img" class="li-icon" mode=""></image>
							<view class="li-name">{{item.name}}</view>
						</view>
						<view class="right">
							<image src="/static/icon/right_arrow_icon_01.png" class="arrow-r" mode=""></image>
						</view>
					</view>
					<view class="li-user">
						<view class="li-item">
							<view class="item-name">{{ $lang('available') }}</view>
							<view class="item-num">{{item.balance || 0}}</view>
						</view>
						<view class="li-item">
							<view class="item-name">{{ $lang('freeze') }}</view>
							<view class="item-num">{{item.balance_freeze || 0}}</view>
						</view>
						<view class="li-item li-right">
							<view class="item-name">{{ $lang('converted') }}</view>
							<view class="item-num">{{item.balance_to_cny || 0}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 底部tabBar -->
		<view class="tabBar-fill"></view>
		<view class="page-bottom" ><diy-bottom-nav :tabIndex="1" ></diy-bottom-nav></view>
		<ns-login ref="login"></ns-login>
		<loading-cover v-if="token" ref="loadingCover"></loading-cover>
	</view>
</template>

<script>
import diyBottomNav from '@/components/diy-bottom-nav/diy-bottom-nav.vue';
import headerTop from '@/components/headerTop.vue'
import globalConfig from '@/common/js/golbalConfig.js';

export default {
  data() {
		return {
			balanceInfo: {
				balance: 0,
				balance_money: 0
			},
			withdrawConfig: null,
			memberrechargeConfig: null,
			walletObj: {},
			walletArr: [],
			userInfo: {},
			token: '',
		};
	},
	components: {
		headerTop,
		diyBottomNav
	},
	mixins: [globalConfig],
	onLoad(){
		this.token = uni.getStorageSync('token') || ''; 
		if (uni.getStorageSync('token')) {
			// return this.$refs.login.open('/otherpages/member/balance/balance');
			this.userInfo = uni.getStorageSync('userInfo')
			this.getWallet();
		}
	},
	onShow() {
		// 刷新多语言
		this.$langConfig.refresh();
		// if (!uni.getStorageSync('token')) {
		// 	this.$refs.login.open('/otherpages/member/balance/balance');
		// }
		// this.getUserInfo();
		// this.getWithdrawConfig();
		// this.getMemberrechargeConfig();
	},
	methods: {
		// 获取资产详情
		getWallet(){
			this.$api.sendRequest({
				url: '/api/wallet/index',
				method: 'get',
				success: res=> {
					if(res.code == 0){
						this.walletObj = res.data;
						this.walletArr = this.walletObj.wallet;
						// this.walletArr.push(...this.walletArr)
					}
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				},
				fail:err=>{
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
			})
		},
		// 跳转详情路由
		toDetail(cid,name){
			if (!uni.getStorageSync('token')) {
				return this.$refs.login.open('/otherpages/member/balance/balance');
			}
			uni.navigateTo({
				url: `/pages/member/blance/data?cid=${cid}&headName=${name}`,
			})
		},
		toRoute(url){
			if (!uni.getStorageSync('token')) {
				return this.$refs.login.open('/otherpages/member/balance/balance');
			}
			console.log(url)
			uni.navigateTo({
				url: url,
			})
		},
		
		toWithdrawal() {
			this.$util.redirectTo('/otherpages/member/apply_withdrawal/apply_withdrawal');
		},
		toOrderList() {
			this.$util.redirectTo('/otherpages/recharge/order_list/order_list');
		},
		toBalanceDetail() {
			this.$util.redirectTo('/otherpages/member/balance_detail/balance_detail');
		},
		toList() {
			this.$util.redirectTo('/otherpages/recharge/list/list');
		},
		//获取余额信息
		getUserInfo() {
			this.$api.sendRequest({
				url: '/api/memberaccount/info',
				data: {
					account_type: 'balance,balance_money'
				},
				success: res => {
					if (res.data) {
						this.balanceInfo = res.data;
					} else {
						this.$util.showToast({
							title: res.message
						});
					}
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				},
				fail: res => {
					mescroll.endErr();
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
			});
		},
		/**
		 * 获取余额提现配置
		 */
		getWithdrawConfig() {
			this.$api.sendRequest({
				url: '/api/memberwithdraw/config',
				success: res => {
					if (res.code >= 0 && res.data) {
						this.withdrawConfig = res.data;
					}
				}
			});
		},
		/**
		 * 获取充值提现配置
		 */
		getMemberrechargeConfig() {
			this.$api.sendRequest({
				url: '/memberrecharge/api/memberrecharge/config',
				success: res => {
					if (res.code >= 0 && res.data) {
						this.memberrechargeConfig = res.data;
					}
				}
			});
		}
	},
	onBackPress(options) {
		if (options.from === 'navigateBack') {
			return false;
		}
		this.$util.redirectTo('/pages/member/index/index', {}, 'reLaunch');
		return true;
	}
};
</script>

<style lang="scss" scoped>
// page {
// 	padding: 20rpx 30rpx 0;
// }
.tabBar-fill {
	height: calc(constant(safe-area-inset-bottom) + 56px);
	height: calc(env(safe-area-inset-bottom) + 56px);
}

.balance-wrap {
	border-radius: 10rpx;
	width: 100%;
	padding: 52rpx 30rpx 40rpx;
	box-sizing: border-box;

	.balance-top {
		.balance-tips {
			display: flex;
			align-items: center;

			text {
				font-size: $font-size-base;
				font-weight: 500;
				color: #ffffff;
				line-height: 1;
				margin-right: 10rpx;
			}

			image {
				width: 30rpx;
				height: 19rpx;
			}

			.iconyincang {
				vertical-align: middle;
				font-size: 40rpx;
			}
		}

		.all-alance {
			font-size: 50rpx;
			line-height: 1;
			color: #ffffff;
			margin-top: 33rpx;
		}

		.withdraw-btn {
			height: 54rpx;
			line-height: 54rpx;

			border-radius: 100rpx 0 0 100rpx;
			padding: 2rpx 40rpx;
			position: absolute;
			right: 0;
			background: #31bb6d;
			color: #fff !important;
		}

		.all-alance {
			line-height: 1;
			font-size: 50rpx;
			font-weight: 500;
		}
	}

	.balance-bottom {
		flex: 2;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-right: 104rpx;

		.balance-bottom-item {
			display: flex;
			flex-direction: column;
			justify-content: center;

			.balance-title {
				font-size: $font-size-base;
				margin-bottom: 10rpx;
				font-weight: 500;
				color: $color-tip;
			}

			.balance {
				line-height: 1;
				font-size: $font-size-toolbar;
				color: #ffffff;
			}
		}
	}
}

.balance_other {
	display: flex;
	margin-top: 76rpx;
	align-items: center;

	.balance_allow,
	.balance_unallow {
		view:first-child {
			font-size: $font-size-base;
			color: #ffffff;
			line-height: 1;
		}

		view:last-child {
			color: #ffffff;
			line-height: 1;
			margin-top: 20rpx;
		}
	}

	.balance-split {
		width: 1rpx;
		height: 47rpx;
		background-color: #ffffff;
		margin-left: 96rpx;
		margin-right: 64rpx;
	}
}

.action_recode {
	margin-top: 20rpx;
	background-color: #ffffff;
	border-radius: 10rpx;
	padding: 0 30rpx;

	> view {
		padding: 22rpx 0;
		display: flex;
		align-items: center;
		position: relative;

		&:first-child {
			border-bottom: 1px solid #eeeeee;
		}

		image {
			width: 55rpx;
			height: 55rpx;
			margin-right: 14rpx;
		}

		text {
			color: $color-title;
		}

		text.iconfont {
			position: absolute;
			font-size: $font-size-base;
			color: $color-tip;
			right: 0;
		}
	}
}

.action {
	position: fixed;
	bottom: 44rpx;
	padding-bottom: constant(safe-area-inset-bottom); //兼容IOS < 11.2
	padding-bottom: env(safe-area-inset-bottom); //兼容IOS > 11.2
	width: calc(100% - 60rpx);
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	margin-top: 100rpx;
	padding-bottom: 30rpx;

	.recharge {
		color: #ffffff;
		width: 80%;
		border-radius: 50rpx;
		text-align: center;
		padding: 20rpx 0;
	}

	> view {
		margin-top: 30rpx;
		text-align: center;
		height: 80rpx;
		line-height: 80rpx;
		width: 500rpx;
		box-sizing: border-box;
		border-radius: 40rpx;
		color: #fff;
	}

	.withdraw {
		border: 1px solid;
	}
}

.balance-other-info {
	margin-top: 50rpx;
	width: 100%;
	display: flex;
	justify-content: center;
	align-items: center;
	top: 750rpx;
	margin-top: 50rpx;

	.balance-detail {
		line-height: 1;
		padding: 0 20rpx;
		font-size: $font-size-tag;
	}

	.recharge-record {
		line-height: 1;
		padding: 0 20rpx;
		font-size: $font-size-tag;
	}
}

.balance-xian {
	width: 2rpx;
	height: 20rpx;
	background-color: #383838;
}

.balance-title {
	color: rgba(255, 255, 255, 0.7);
}

// new


.blance-header {
	width: 100%;
	background: #fff;
	padding: 50rpx 32rpx 36rpx;
	box-sizing: border-box;
	// padding-top: -100rpx;
	.header-wrap {
		width: 100%;
		background: linear-gradient(270deg, #FF7979 0%, #FF4F4D 100%);
		border-radius: 10rpx;
		padding: 34rpx 28rpx 24rpx;
		box-sizing: border-box;
		.wrap-box {
			display: grid;
			align-items: center;
			grid-template-columns: 1fr 1fr 1fr;
			padding-bottom: 24rpx;
			border-bottom: 2rpx solid #FF8988;
			.wrap {
				color: #fff;
				font-family: PingFangSC-Regular, PingFang SC;
				font-size: 24rpx;
				.num {
					margin-top: 14rpx;
					font-weight: 600;
					line-height: 34rpx;
				}
			}
			.wrap-r {
				text-align: right;
			}	
			.wrap-c {
				text-align: center;
			}
		}
				
		.wrap-text {
			color: #fff;
		}
		
		.wrap-bom {
			margin-top: 24rpx;
			display: grid;
			align-items: center;
			// justify-content: space-between;
			grid-template-columns: 1fr 1fr;
			padding: 0px 38rpx;
			box-sizing: border-box;
			.bom-box {
				display: flex;
				align-items: center;
				height: 56rpx;
				.bom-icon {
					width: 56rpx;
					height: 56rpx;
					margin-right: 18rpx;
				}
				font-size: 28rpx;
				font-weight: 500;
				color: #fff;
			}
			.bom-r {
				justify-content: flex-end;
			}
			.wrap-bd {
				border-right: 2rpx solid #FF8988;
			}
		}
	}
}

.wrap-text {
	color: #fff;
}

.blance-content {
	width: 100%;
	padding: 28rpx 32rpx;
	box-sizing: border-box;
	.user-box {
		width: 100%;
		background: #FFFFFF;
		border-radius: 10rpx;
		padding: 24rpx 28rpx 0px;
		box-sizing: border-box;
		.user-price {
			font-size: 48rpx;
			color: #282828;
			font-weight: 600;
			line-height: 66rpx;
			margin: 10rpx 0px 6rpx;
		}
		.price {
			font-size: 24rpx;
			color: #282828;
			line-height: 34rpx;
		}
		
		.user-wrap {
			margin-top: 22rpx;
			padding: 20rpx 0px 28rpx;
			border-top: 2rpx solid #EEEDF2;
			display: grid;
			grid-template-columns: 1fr 1fr 1fr;
			align-items: center;
			.user-item {
				display: flex;
				align-items: center;
				justify-content: center;
				height: 56rpx;
				.bi-icon {
					width: 56rpx;
					height: 56rpx;
				}
				.user-text {
					font-weight: 500;
					font-size: 28rpx;
					color: #282828;
					line-height: 40rpx;
					margin-left: 18rpx;
				}
			}
			.user-bd {
				border-right: 2rpx solid #EEEDF2;
			}
		}
	}
	
	.h-title {
		font-size: 28rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 600;
		color: #353535;
		line-height: 40rpx;
		padding: 34rpx 0px 30rpx;
	}
	
	.blance-ul {
		.blance-li {
			width: 100%;
			background: #FFFFFF;
			border-radius: 10rpx;
			padding: 30rpx 28rpx 24rpx;
			box-sizing: border-box;
			margin-bottom: 28rpx;
			.li-top {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-bottom: 26rpx;
				.left {
					display: flex;
					align-items: center;
					.li-icon {
						width: 48rpx;
						height: 48rpx;
						display: block;
						border-radius: 50%;
					}
					.li-name {
						font-size: 28rpx;
						font-family: PingFangSC-Semibold, PingFang SC;
						font-weight: 600;
						color: #353535;
						line-height: 40rpx;
						margin-left: 18rpx;
					}
				}
			}
			
			.li-user {
				display: grid;
				grid-template-columns: 1fr 1fr 1fr;
				align-items: center;
				.li-item {
					.item-name {
						font-size: 24rpx;
						color: #92969E;
						line-height: 34rpx;
						margin-bottom: 8rpx;
					}
					.item-num {
						font-size: 24rpx;
						color: #292929;
						font-weight: 600;
						line-height: 40rpx;
					}
				}
				.li-right {
					text-align: right;
				}
			}
		}
	}
}


</style>
